
<template name="sendcar">
	<!-- 盘点物资列表 -->
	<view class="mypage">
		<view class="cu-bar search bg-white">
			<view class="search-form round">
				<text class="cuIcon-search"></text>
				<input type="text" placeholder="输入物资名称" v-model="keyword"></input>
			</view>
			<view class="action">
				<button class="cu-btn bg-blue shadow-blur round" @tap="handelSearch">搜索</button>
			</view>
		</view>

		<view class="card-list-wrapper">
			<view class="card-list-row radius shadow-warp bg-white margin-top" v-for="(item,index) in planList" :key="index"
			 @click="openDetail(index)">

				<view class="flex-just-between bottom-border top-wrap">
					<text class="text-blue text-bold">单号：{{ item.PK_MATERIAL || '' }}</text>
					<view class="">
						<!-- cu-capsule radius -->
						<!-- <view class='cu-tag bg-blue sm'>
							<text class='cuIcon-medal'></text>
						</view> -->
						<view class="cu-tag bg-blue sm" v-if="item.INVENTORYSTATUS==0">
							正常
						</view>
						
						<view class="cu-tag bg-green sm" v-if="item.INVENTORYSTATUS==1">
							盘盈
						</view>
						
						<view class="cu-tag bg-red sm" v-if="item.INVENTORYSTATUS==2">
							盘亏
						</view>
						
					</view>
				</view>

				<view class="card-list-row-1 margin-top">
					<text>名称：{{ item.MATERIALNAME || '' }}</text>
				</view>

				<view class="card-list-row-1">
					<text>规格：{{ item.MATSPEC  || '' }} </text>
				</view>
				
				<view class="card-list-row-1">
					<text>条码：{{ item.BARCODE  || '' }}   </text>
				</view>
				<view class="card-list-row-1">
					<text>货位：{{ item.STATIONNAME  || '' }}   </text>
				</view>
				
				<view class="card-list-row-1">
					<view class="">
						状态：
						<text :class="item.IsInventory==1? 'text-blue' : 'text-red'">{{ item.IsInventory==1? '已盘点': '未盘点' }}   </text>
					</view>
					<!-- <text >状态：{{ item.IsInventory==1 '已盘点'  || '未盘点' }}   </text> -->
				</view>
				
				<view class="card-list-row-1">
					<text>库存数量：{{ item.KNUM || item.NNUM || '0' }}  {{ item.UNIT=='null'?'' : item.UNIT }} </text>
				</view>

				<view class="position-a checkFlag" v-if="item.ischeck">
					<text class='cuIcon-squarecheckfill text-blue'></text>
				</view>

				<!-- <view class="flex-just-between top-border margin-top btn-wrap">
					<button class="cu-btn round lines-gray" >出库</button>
					<button class="cu-btn round lines-gray" >移位</button>
				</view> -->

			</view>

		</view>

		<view class="next-btn-wrap position-f" @click="nextTap">
			<button class="big-btn bg-green shadow-blur">
				<text class="cuIcon-refresharrow text-bold"></text>
			</button>
		</view>
		
		<modal title="高级查询" placeholder=""
		 :isShow='isShowModal'
			@cancelModal='cancelModal'
			@okModal='okModal'
		></modal>
		
	</view>

</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	import api from '@/common/api.js';
	import utils from '@/common/util.js';
	import modal from '@/components/modal/modal_mater.vue'
	let query = {
		"category": "ST_INVENTORY",
		"page": 1,
		"rows": "10",
		"sidx":"",
		"sord":"desc",
		"queryJson": {},
		"userId": "",
		"account": "admin"
	}
	let _self, menuType, page = 1,
		total = 1,BILLNO = '', webView ,
		queryJson = {
			PK_INVENTORY: ''
		};
	export default {
		computed: mapState(['userInfo', 'baseUrl']),
		data() {
			return {
				planList: [],
				keyword: '',
				isAll : false ,
				isShowModal: false ,
				queryType: 0 ,
			};
		},

		onLoad(p) {
			// #ifdef APP-PLUS
			webView = this.$mp.page.$getAppWebview();
			// #endif
			console.log(33, p)
			this.queryType = p.type
			queryJson.STATIONNAME = p.no ==1? '' : p.id
			queryJson.PK_ORG = p.PK_ORG
			_self = this
			query.userId = _self.userInfo.UserId
			query.account = _self.userInfo.Account
			BILLNO = p.id
			_self.planList = [];
			page = 1;
			total = 1 ;
			this.getList()
			uni.$on("updateList",res=>{
				page = 1;
				total = 1 ;
				_self.planList = [];
				this.getList()
				console.log('刷新111');
				webView.setTitleNViewButtonStyle(1, {
				    text: '全选',  
				});
			})
		},
		onUnload(){
		    uni.$off('updateList')  //在此生命周期里销毁地址改变事件的监听
		},
		components:{
			modal
		},
		onNavigationBarButtonTap(e){
			// console.log(e);
			if(e.index == 0){
				this.openScan()
			}else {
				this.isAll = !this.isAll
				if(this.isAll){
					webView.setTitleNViewButtonStyle(1, {  
					    text: '取消',  
					});  
				}else{
					webView.setTitleNViewButtonStyle(1, {
					    text: '全选',  
					});
				}
				this.allChoose()
			}
		},
		//下拉刷新
		onPullDownRefresh: function() {
			// 重置分页及数据
			page = 1;
			total = 1;
			_self.planList = [];
			this.getList();
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
			uni.showToast({
				"title": "数据已刷新",
				icon: "none"
			});
		},
		// 加载更多
		onReachBottom: function() {
			this.getList();
		},
		methods: {
			openDetail: function(e) {
				_self.planList[e].ischeck = !_self.planList[e].ischeck;
			},
			
			// 全选
			allChoose(){
				let arr = _self.planList.map(item=>{
					item.ischeck = this.isAll
					 return item ;
				})
				// console.log(this.isAll);
				this.planList = arr ;
			},
			
			handelSearch() {
				page = 1;
				total = 1;
				_self.planList = [];
				this.getList();
			},
			nextTap() {
				let t = [];
				_self.planList.forEach((item) => {
					if (item.ischeck) {
						t.push(item)
					}
				});
				
				if(!t.length) return utils.tips('请选择物资')
				
				if(this.queryType==999){
					BILLNO = 'Y'
				}
				let uu = '/pages/tab01/inventory/new_submit_mater?id='+BILLNO+'&data=';
				let aa = utils.URIErroeTo( JSON.stringify(t) ) ;
				uni.navigateTo({
					url: uu + encodeURIComponent(aa)
				})
			},
			getList() {
				if (page > total) {
					return utils.tips('没有数据了')
				}
				query.page = page;
				if(!this.queryType || this.queryType !=999){
					queryJson.PK_INVENTORY = BILLNO
					queryJson.MATERIALNAME= _self.keyword
				}
				queryJson.VNAME=_self.keyword
				if(this.queryType==999){
					queryJson.MATERIALNAME= _self.keyword
				}
				query.queryJson = JSON.stringify(queryJson);
				console.log(query);
				// utils.mShowLoading();
				let URL  = this.queryType==999?'/api/APPCommon//GetPageList_StockInfo': api.apiPublic.getMaterList ;
				this.axios({
					url:URL ,
					data:query,
					isLoading:1
				}).then(res=>{
					console.log(991,res);
					let { Result } = res ;
					let array = Result.rows.map((item) => {
								item.ischeck = false;
								return item;
					})
					if(page == 1){
						_self.setPageTitle('盘点物资列表(' + Result.records + ')')
						total = Result.total
					}
					_self.planList = [..._self.planList, ...array ] 
					page++
				})
			},
			setPageTitle(d) {
				uni.setNavigationBarTitle({
					title: d
				});
			},
			
			// 控制高级查询条件
			cancelModal(){
				this.isShowModal = false
			},
			okModal(val){
				this.cancelModal();
				queryJson = {...val};
				page = 1;
				total = 1;
				_self.planList = [];
				this.getList();
			},
			
			// 扫码物资事件
			openScan(){
				let URL =  api.apiPublic.ScanCode;
				this.$utils.Scan(URL, data => {
					console.log(data);
					let uu = '/pages/tab01/inventory/new_submit_mater?id='+BILLNO+'&data=';
					uni.navigateTo({
						url: uu + encodeURIComponent(JSON.stringify([data]))
					})
					
				},BILLNO);
				
			},
			
		}
	}
</script>

<style scoped>
	.height50 {
		height: 50px;
	}

	.card-list-wrapper {
		width: 710upx;
		height: 100upx;
		margin: 0 auto;

	}

	.card-list-row {
		padding: 20upx;
	}

	.card-list-row-1 {
		padding: 10upx 0;
	}

	.top-border {
		border-top: 1upx solid rgba(0, 0, 0, .1);
	}

	.top-wrap {
		padding-bottom: 20upx;
	}

	.bottom-border {
		border-bottom: 1upx solid rgba(0, 0, 0, .1);
	}

	.btn-wrap {
		padding-top: 20upx;
	}

	.checkFlag {
		top: 50%;
		right: 20upx;
		font-size: 40upx;
	}

	.next-btn-wrap {
		position: fixed;
		right: 50upx;
		bottom: 100upx;
	}

	.big-btn {
		width: 100upx;
		height: 100upx;
		border-radius: 50upx;
		font-size: 40upx;
	}
</style>
